package everyday;

/**
 * @Author: Siantar
 * @Date: 2023-06-29-21:47
 * @Description: 1.0
 */
public class T2485 {
    public int pivotInteger(int n) {
        int left = 0, right = n;
        while (left < right) {
            int mid = (left + right) / 2;
            int l = (1 + mid - 1) * (mid - 1 - 1);
            int r = (n + mid - 1) * (n - mid + 1);
            if (l > r) {
                right = mid - 1;
            } else if (l < r) {
                left = mid + 1;
            } else {
                return mid;
            }
        }
        return -1;
    }
}
